/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * QLTV.java
 *
 * Created on Oct 5, 2010, 11:28:09 PM
 */

package qltv;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.*;
import java.util.Vector;
//import java.util.
/**
 *
 * @author DELL
 */
public class QLTV extends javax.swing.JFrame {

    /** Creates new form QLTV */
    public QLTV() {
        initComponents();        
        loaddangnhap();
        loadqlms();
        loadqlts();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tbtag = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        PNms = new javax.swing.JPanel();
        PNktdg = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        tb_qlms_madg = new javax.swing.JTextField();
        bt_qlms_ktdg = new javax.swing.JButton();
        jLabel12 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        tb_qlms_hoten = new javax.swing.JTextField();
        tb_qlms_doituong = new javax.swing.JTextField();
        tb_qlms_diachi = new javax.swing.JTextField();
        tb_qlms_ngaysinh = new javax.swing.JTextField();
        tb_qlms_gioitinh = new javax.swing.JTextField();
        tb_qlms_ngayhethan = new javax.swing.JTextField();
        jLabel40 = new javax.swing.JLabel();
        PNkts = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        tb_qlms_mapm = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        tb_qlms_mas = new javax.swing.JTextField();
        bt_qlms_ktsach = new javax.swing.JButton();
        jLabel19 = new javax.swing.JLabel();
        tb_qlms_tensach = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        tb_qlms_tacgia = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        tb_qlms_linhvuc = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        tb_qlms_ngonngu = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        tb_qlms_gia = new javax.swing.JTextField();
        tb_qlms_nhaxuatban = new javax.swing.JTextField();
        bt_qlms_chomuon = new javax.swing.JButton();
        bt_qlms_huythaotac = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        PNts = new javax.swing.JPanel();
        jLabel25 = new javax.swing.JLabel();
        tb_qlts_madg = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        tb_qlts_tendg = new javax.swing.JTextField();
        jLabel27 = new javax.swing.JLabel();
        tb_qlts_sosachmuon = new javax.swing.JTextField();
        cb_qlts_matsach = new javax.swing.JCheckBox();
        jLabel28 = new javax.swing.JLabel();
        tb_qlts_mas = new javax.swing.JTextField();
        jLabel29 = new javax.swing.JLabel();
        tb_qlts_songayquahan = new javax.swing.JTextField();
        jLabel30 = new javax.swing.JLabel();
        tb_qlts_xuphat = new javax.swing.JTextField();
        bt_qlts_ktdg = new javax.swing.JButton();
        bt_qlts_kts = new javax.swing.JButton();
        bt_qlts_ts = new javax.swing.JButton();
        bt_qlts_huythaotac = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tb_xemkq = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        PNqldg = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        table_DOCGIA = new javax.swing.JTable();
        bt_XOA = new javax.swing.JButton();
        bt_SUA = new javax.swing.JButton();
        bt_THEM = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        PNqls = new javax.swing.JPanel();
        tb_qls_gia = new javax.swing.JTextField();
        jLabel31 = new javax.swing.JLabel();
        jLabel32 = new javax.swing.JLabel();
        jLabel33 = new javax.swing.JLabel();
        tb_qls_tensach = new javax.swing.JTextField();
        jLabel34 = new javax.swing.JLabel();
        jLabel35 = new javax.swing.JLabel();
        jLabel36 = new javax.swing.JLabel();
        tb_qls_masach = new javax.swing.JTextField();
        jLabel37 = new javax.swing.JLabel();
        bt_qls_them = new javax.swing.JButton();
        bt_qls_sua = new javax.swing.JButton();
        bt_qls_xoa = new javax.swing.JButton();
        cb_qls_ngonngu = new javax.swing.JComboBox();
        cb_qls_nhaxuatban = new javax.swing.JComboBox();
        cb_qls_linhvuc = new javax.swing.JComboBox();
        jLabel39 = new javax.swing.JLabel();
        cb_qls_nhacungcap = new javax.swing.JComboBox();
        cb_qls_tacgia = new javax.swing.JComboBox();
        tbun = new javax.swing.JTextField();
        tbpw = new javax.swing.JPasswordField();
        jLabel1 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        btdangnhap = new javax.swing.JButton();
        lbketnoi = new javax.swing.JLabel();
        btdangxuat = new javax.swing.JButton();
        jLabel38 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        PNms.setBackground(new java.awt.Color(0, 51, 255));

        jLabel9.setText("Mã độc giả");

        bt_qlms_ktdg.setText("Kiểm tra độc giả");
        bt_qlms_ktdg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_qlms_ktdgActionPerformed(evt);
            }
        });

        jLabel12.setText("........................................................................");

        jLabel14.setText("Họ Tên");

        jLabel15.setText("Đối Tượng");

        jLabel16.setText("Địa Chỉ");

        jLabel17.setText("Ngày Sinh");

        jLabel18.setText("Giới Tính");

        jLabel40.setText("Ngày hết hạn");

        javax.swing.GroupLayout PNktdgLayout = new javax.swing.GroupLayout(PNktdg);
        PNktdg.setLayout(PNktdgLayout);
        PNktdgLayout.setHorizontalGroup(
            PNktdgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PNktdgLayout.createSequentialGroup()
                .addComponent(jLabel9)
                .addGap(18, 18, 18)
                .addComponent(tb_qlms_madg, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(bt_qlms_ktdg)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PNktdgLayout.createSequentialGroup()
                .addContainerGap(19, Short.MAX_VALUE)
                .addComponent(jLabel12)
                .addGap(20, 20, 20))
            .addGroup(PNktdgLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PNktdgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel16)
                    .addComponent(jLabel15)
                    .addComponent(jLabel14)
                    .addComponent(jLabel17)
                    .addComponent(jLabel18)
                    .addComponent(jLabel40))
                .addGap(27, 27, 27)
                .addGroup(PNktdgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PNktdgLayout.createSequentialGroup()
                        .addGroup(PNktdgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(tb_qlms_ngayhethan, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
                            .addComponent(tb_qlms_gioitinh, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
                            .addComponent(tb_qlms_ngaysinh, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE))
                        .addGap(120, 120, 120))
                    .addGroup(PNktdgLayout.createSequentialGroup()
                        .addComponent(tb_qlms_hoten, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(PNktdgLayout.createSequentialGroup()
                        .addGroup(PNktdgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tb_qlms_doituong, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
                            .addComponent(tb_qlms_diachi, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE))
                        .addGap(120, 120, 120))))
        );
        PNktdgLayout.setVerticalGroup(
            PNktdgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PNktdgLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PNktdgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(tb_qlms_madg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bt_qlms_ktdg))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PNktdgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(tb_qlms_hoten, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PNktdgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel15)
                    .addComponent(tb_qlms_doituong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PNktdgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(tb_qlms_diachi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PNktdgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(tb_qlms_ngaysinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PNktdgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel18)
                    .addComponent(tb_qlms_gioitinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PNktdgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tb_qlms_ngayhethan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel40))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel10.setText("Mã Phiếu Mượn");

        jLabel11.setText("Mã sách");

        jLabel13.setText("........................................................................");

        bt_qlms_ktsach.setText("Kiểm tra sách");
        bt_qlms_ktsach.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_qlms_ktsachActionPerformed(evt);
            }
        });

        jLabel19.setText("Tên Sách");

        jLabel20.setText("Tác Giả");

        jLabel21.setText("Lĩnh Vực");

        jLabel22.setText("Ngôn Ngữ");

        jLabel23.setText("Giá");

        jLabel24.setText("Nhà Xuất bản");

        javax.swing.GroupLayout PNktsLayout = new javax.swing.GroupLayout(PNkts);
        PNkts.setLayout(PNktsLayout);
        PNktsLayout.setHorizontalGroup(
            PNktsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PNktsLayout.createSequentialGroup()
                .addGap(2, 2, 2)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(tb_qlms_mapm, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel11)
                .addGap(12, 12, 12)
                .addComponent(tb_qlms_mas, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(bt_qlms_ktsach))
            .addGroup(PNktsLayout.createSequentialGroup()
                .addGap(52, 52, 52)
                .addComponent(jLabel13))
            .addGroup(PNktsLayout.createSequentialGroup()
                .addGroup(PNktsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, PNktsLayout.createSequentialGroup()
                        .addComponent(jLabel24)
                        .addGap(52, 52, 52)
                        .addComponent(tb_qlms_nhaxuatban))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, PNktsLayout.createSequentialGroup()
                        .addGroup(PNktsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel19)
                            .addComponent(jLabel20)
                            .addComponent(jLabel21)
                            .addComponent(jLabel22)
                            .addComponent(jLabel23))
                        .addGap(69, 69, 69)
                        .addGroup(PNktsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(tb_qlms_gia)
                            .addComponent(tb_qlms_ngonngu)
                            .addComponent(tb_qlms_linhvuc)
                            .addComponent(tb_qlms_tacgia)
                            .addComponent(tb_qlms_tensach, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE))))
                .addContainerGap(159, Short.MAX_VALUE))
        );
        PNktsLayout.setVerticalGroup(
            PNktsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PNktsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PNktsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tb_qlms_mas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bt_qlms_ktsach)
                    .addComponent(jLabel10)
                    .addComponent(tb_qlms_mapm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel13)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PNktsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel19)
                    .addComponent(tb_qlms_tensach, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PNktsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel20)
                    .addComponent(tb_qlms_tacgia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PNktsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel21)
                    .addComponent(tb_qlms_linhvuc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PNktsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel22)
                    .addComponent(tb_qlms_ngonngu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PNktsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tb_qlms_gia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel23))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PNktsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel24)
                    .addComponent(tb_qlms_nhaxuatban, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        bt_qlms_chomuon.setText("Cho Mượn");
        bt_qlms_chomuon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_qlms_chomuonActionPerformed(evt);
            }
        });

        bt_qlms_huythaotac.setText("Hủy Thao Tác");
        bt_qlms_huythaotac.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_qlms_huythaotacActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout PNmsLayout = new javax.swing.GroupLayout(PNms);
        PNms.setLayout(PNmsLayout);
        PNmsLayout.setHorizontalGroup(
            PNmsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PNmsLayout.createSequentialGroup()
                .addGroup(PNmsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(PNmsLayout.createSequentialGroup()
                        .addComponent(PNktdg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(PNkts, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(PNmsLayout.createSequentialGroup()
                        .addGap(207, 207, 207)
                        .addComponent(bt_qlms_chomuon, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(77, 77, 77)
                        .addComponent(bt_qlms_huythaotac)))
                .addContainerGap())
        );
        PNmsLayout.setVerticalGroup(
            PNmsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PNmsLayout.createSequentialGroup()
                .addGroup(PNmsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(PNmsLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(PNkts, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(PNktdg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(PNmsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bt_qlms_huythaotac)
                    .addComponent(bt_qlms_chomuon))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(PNms, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(PNms, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        tbtag.addTab("Quản Lý Mượn Sách", jPanel2);

        PNts.setBackground(new java.awt.Color(0, 51, 255));

        jLabel25.setText("Mã độc giả");

        jLabel26.setText("Tên độc giả");

        jLabel27.setText("Số sách mượn");

        cb_qlts_matsach.setText("mất sách");

        jLabel28.setText("Mã sách");

        jLabel29.setText("Số ngày quá hạn");

        jLabel30.setText("Xử phạt");

        bt_qlts_ktdg.setText("Kiểm tra độc giả");
        bt_qlts_ktdg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_qlts_ktdgActionPerformed(evt);
            }
        });

        bt_qlts_kts.setText("Kiểm tra sách");
        bt_qlts_kts.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_qlts_ktsActionPerformed(evt);
            }
        });

        bt_qlts_ts.setText("Trả sách");
        bt_qlts_ts.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_qlts_tsActionPerformed(evt);
            }
        });

        bt_qlts_huythaotac.setText("Hủy Thao Tác");
        bt_qlts_huythaotac.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_qlts_huythaotacActionPerformed(evt);
            }
        });

        tb_xemkq.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Mã Sách", "Tên Sách", "Ngày Mượn"
            }
        ));
        jScrollPane1.setViewportView(tb_xemkq);

        javax.swing.GroupLayout PNtsLayout = new javax.swing.GroupLayout(PNts);
        PNts.setLayout(PNtsLayout);
        PNtsLayout.setHorizontalGroup(
            PNtsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PNtsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PNtsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(PNtsLayout.createSequentialGroup()
                        .addGroup(PNtsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel25)
                            .addComponent(jLabel28))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(PNtsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(tb_qlts_mas)
                            .addComponent(tb_qlts_madg, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(34, 34, 34)
                        .addGroup(PNtsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel29)
                            .addComponent(jLabel26))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(PNtsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(tb_qlts_tendg, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tb_qlts_songayquahan))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(PNtsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel27)
                            .addComponent(jLabel30))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(PNtsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(PNtsLayout.createSequentialGroup()
                                .addComponent(tb_qlts_sosachmuon, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(cb_qlts_matsach))
                            .addComponent(tb_qlts_xuphat, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(PNtsLayout.createSequentialGroup()
                        .addComponent(bt_qlts_ktdg)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(bt_qlts_kts, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(bt_qlts_ts)
                        .addGap(39, 39, 39)
                        .addComponent(bt_qlts_huythaotac))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 452, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(124, Short.MAX_VALUE))
        );
        PNtsLayout.setVerticalGroup(
            PNtsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PNtsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PNtsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(PNtsLayout.createSequentialGroup()
                        .addComponent(tb_qlts_madg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(PNtsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tb_qlts_mas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel29)
                            .addComponent(tb_qlts_songayquahan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tb_qlts_xuphat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel30)))
                    .addGroup(PNtsLayout.createSequentialGroup()
                        .addGroup(PNtsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel25)
                            .addComponent(jLabel26)
                            .addComponent(jLabel27)
                            .addComponent(tb_qlts_sosachmuon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cb_qlts_matsach)
                            .addComponent(tb_qlts_tendg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jLabel28)))
                .addGap(42, 42, 42)
                .addGroup(PNtsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bt_qlts_ktdg, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bt_qlts_kts)
                    .addComponent(bt_qlts_ts)
                    .addComponent(bt_qlts_huythaotac))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(27, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(PNts, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(PNts, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        tbtag.addTab("Quản Lý Trả Sách", jPanel3);

        PNqldg.setBackground(new java.awt.Color(0, 102, 255));

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Danh sách độc giả:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        table_DOCGIA.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        table_DOCGIA.setColumnSelectionAllowed(true);
        jScrollPane2.setViewportView(table_DOCGIA);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 627, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(32, Short.MAX_VALUE))
        );

        bt_XOA.setFont(new java.awt.Font("Tahoma", 1, 12));
        bt_XOA.setText("XÓA");
        bt_XOA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_XOAActionPerformed(evt);
            }
        });

        bt_SUA.setFont(new java.awt.Font("Tahoma", 1, 12));
        bt_SUA.setText("SỬA");
        bt_SUA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_SUAActionPerformed(evt);
            }
        });

        bt_THEM.setFont(new java.awt.Font("Tahoma", 1, 12));
        bt_THEM.setText("THÊM");
        bt_THEM.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_THEMActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout PNqldgLayout = new javax.swing.GroupLayout(PNqldg);
        PNqldg.setLayout(PNqldgLayout);
        PNqldgLayout.setHorizontalGroup(
            PNqldgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 755, Short.MAX_VALUE)
            .addGroup(PNqldgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(PNqldgLayout.createSequentialGroup()
                    .addGroup(PNqldgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(PNqldgLayout.createSequentialGroup()
                            .addGap(448, 448, 448)
                            .addComponent(bt_THEM)
                            .addGap(26, 26, 26)
                            .addComponent(bt_XOA, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(26, 26, 26)
                            .addComponent(bt_SUA, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(PNqldgLayout.createSequentialGroup()
                            .addGap(48, 48, 48)
                            .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(48, Short.MAX_VALUE)))
        );
        PNqldgLayout.setVerticalGroup(
            PNqldgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 358, Short.MAX_VALUE)
            .addGroup(PNqldgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PNqldgLayout.createSequentialGroup()
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(PNqldgLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(bt_THEM)
                        .addComponent(bt_XOA)
                        .addComponent(bt_SUA))
                    .addGap(18, 18, 18)
                    .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(117, 117, 117)))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(PNqldg, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(PNqldg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        tbtag.addTab("Quản Lý Độc Giả", jPanel1);

        PNqls.setBackground(new java.awt.Color(0, 51, 255));

        jLabel31.setText("Tên Sách");

        jLabel32.setText("Nhà Xuất bản");

        jLabel33.setText("Tác Giả");

        jLabel34.setText("Lĩnh Vực");

        jLabel35.setText("Ngôn Ngữ");

        jLabel36.setText("Mã Sách");

        jLabel37.setText("Giá");

        bt_qls_them.setText("Thêm");
        bt_qls_them.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_qls_themActionPerformed(evt);
            }
        });

        bt_qls_sua.setText("Sữa");
        bt_qls_sua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_qls_suaActionPerformed(evt);
            }
        });

        bt_qls_xoa.setText("Xóa");
        bt_qls_xoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_qls_xoaActionPerformed(evt);
            }
        });

        cb_qls_linhvuc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_qls_linhvucActionPerformed(evt);
            }
        });

        jLabel39.setText("Nhà Cung Cấp");

        javax.swing.GroupLayout PNqlsLayout = new javax.swing.GroupLayout(PNqls);
        PNqls.setLayout(PNqlsLayout);
        PNqlsLayout.setHorizontalGroup(
            PNqlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PNqlsLayout.createSequentialGroup()
                .addGap(63, 63, 63)
                .addGroup(PNqlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel33)
                    .addComponent(jLabel31)
                    .addComponent(jLabel36)
                    .addComponent(jLabel37))
                .addGap(39, 39, 39)
                .addGroup(PNqlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(cb_qls_tacgia, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(tb_qls_masach)
                    .addComponent(tb_qls_tensach, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                    .addComponent(tb_qls_gia))
                .addGap(41, 41, 41)
                .addGroup(PNqlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(PNqlsLayout.createSequentialGroup()
                        .addComponent(jLabel34)
                        .addGap(60, 60, 60)
                        .addComponent(cb_qls_linhvuc, 0, 128, Short.MAX_VALUE))
                    .addGroup(PNqlsLayout.createSequentialGroup()
                        .addGroup(PNqlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel35)
                            .addComponent(jLabel32)
                            .addComponent(jLabel39))
                        .addGap(31, 31, 31)
                        .addGroup(PNqlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(cb_qls_nhacungcap, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(cb_qls_nhaxuatban, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(cb_qls_ngonngu, 0, 128, Short.MAX_VALUE))))
                .addContainerGap(188, Short.MAX_VALUE))
            .addGroup(PNqlsLayout.createSequentialGroup()
                .addGap(59, 59, 59)
                .addComponent(bt_qls_them, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(39, 39, 39)
                .addComponent(bt_qls_sua, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(41, 41, 41)
                .addComponent(bt_qls_xoa, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(394, Short.MAX_VALUE))
        );
        PNqlsLayout.setVerticalGroup(
            PNqlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PNqlsLayout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(PNqlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel36)
                    .addComponent(tb_qls_masach, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(PNqlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel35)
                        .addComponent(cb_qls_ngonngu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PNqlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel31)
                    .addGroup(PNqlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(tb_qls_tensach, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel32)
                        .addComponent(cb_qls_nhaxuatban, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PNqlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(PNqlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel33)
                        .addComponent(cb_qls_tacgia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(PNqlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel39)
                        .addComponent(cb_qls_nhacungcap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PNqlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel37)
                    .addGroup(PNqlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(tb_qls_gia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel34)
                        .addComponent(cb_qls_linhvuc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(41, 41, 41)
                .addGroup(PNqlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bt_qls_them, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bt_qls_sua)
                    .addComponent(bt_qls_xoa))
                .addContainerGap(89, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(PNqls, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(PNqls, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        tbtag.addTab("Quản Lý Sách", jPanel4);

        jLabel1.setText("Username");

        jLabel8.setText("Password");

        btdangnhap.setText("Đăng Nhập");
        btdangnhap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btdangnhapActionPerformed(evt);
            }
        });

        lbketnoi.setText("Chưa kết nôi");

        btdangxuat.setText("Đăng Xuất");
        btdangxuat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btdangxuatActionPerformed(evt);
            }
        });

        jLabel38.setFont(new java.awt.Font("Tahoma", 0, 24));
        jLabel38.setText("Quản Lý Thư Viện");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel8))
                        .addGap(33, 33, 33)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(tbun, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tbpw, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(119, 119, 119)
                        .addComponent(jLabel38))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(71, 71, 71)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbketnoi)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(btdangnhap)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btdangxuat)))))
                .addContainerGap(245, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tbtag, javax.swing.GroupLayout.DEFAULT_SIZE, 760, Short.MAX_VALUE)
                .addGap(27, 27, 27))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tbun, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tbpw, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btdangnhap)
                            .addComponent(btdangxuat)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addComponent(jLabel38)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbketnoi)
                .addGap(18, 18, 18)
                .addComponent(tbtag, javax.swing.GroupLayout.PREFERRED_SIZE, 316, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private final String server = "THAOLE-VAIO";
    private final int port = 1433;
    private final String databaseName = "QLTHUVIEN_Nhom7_DACNPM";
    private final String username = "test";
    private final String password = "123456";
    Connection con = null;
   
    //chua lam    //public StringBuffer username= new StringBuffer();
    /*************************
    //phan dang nhap
     *************************
     */

    public String Username;
    public String Password;
    public String manhanvien;
    public String quyenhan;

    public void loaddangnhap()
    {
        PNqldg.setVisible(false);
        PNqls.setVisible(false);
        PNms.setVisible(false);
        PNts.setVisible(false);
        btdangxuat.setVisible(false);   
    }
    private void btdangnhapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btdangnhapActionPerformed
        // TODO add your handling code here:
      try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            try {
                boolean flag = false;
                Username= tbun.getText();
                Password= tbpw.getText();
                // Usernmae ko duoc rong thi ket noi voi database
                
                if(!Username.equals(""))
                {
                    Connection con = DriverManager.getConnection(getURLConnection());
                    Statement stm=con.createStatement();
                    ResultSet rs = stm.executeQuery("SELECT TENDANGNHAP,MANHANVIEN,QUYENHAN FROM NHANVIEN WHERE NHANVIEN.TENDANGNHAP='" + Username +"' AND NHANVIEN.MATKHAU='"+ Password + "'");
                    String s = "";                    
                    while (rs.next())
                    {
                        s = rs.getString(1);
                        manhanvien = rs.getString(2);
                        quyenhan = rs.getString(3);
                        quyenhan=quyenhan.toUpperCase();
                        s=s.toUpperCase();
                        Username=Username.toUpperCase();
                    }
                    if(Username.equals(s.trim()))
                    {                        
                        if (quyenhan.trim().equals("ADMIN"))
                        {
                            PNqldg.setVisible(true);
                            PNqls.setVisible(true);
                            PNms.setVisible(true);
                            PNts.setVisible(true);
                            lbketnoi.setText("Đăng nhập thành công với quyền admin");
                            btdangnhap.setVisible(false);
                            btdangxuat.setVisible(true);
                        
                        }
                        else if(quyenhan.trim().equals("THUKHO"))
                        {
                            PNqldg.setVisible(true);
                            PNqls.setVisible(true);
                            PNms.setVisible(false);
                            PNts.setVisible(false);
                            lbketnoi.setText("Đăng nhập thành công với quyền Thủ Kho");
                            btdangnhap.setVisible(false);
                            btdangxuat.setVisible(true);
                        }
                        else if(quyenhan.trim().equals("MUONTRA"))
                        {
                            PNqldg.setVisible(false);
                            PNqls.setVisible(false);
                            PNms.setVisible(true);
                            PNts.setVisible(true);
                            lbketnoi.setText("Đăng nhập thành công với quyền Mượn Trả");
                            btdangnhap.setVisible(false);
                            btdangxuat.setVisible(true);
                        }
                        else
                        {
                            PNqldg.setVisible(false);
                            PNqls.setVisible(false);
                            PNms.setVisible(false);
                            PNts.setVisible(false);
                            lbketnoi.setText("Đăng nhập ko thành công");
                            btdangnhap.setVisible(true);
                            btdangxuat.setVisible(false);
                        }
                    }
                    else lbketnoi.setText("ko thanh cong");
                }            
            } catch (SQLException ex) {
                Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_btdangnhapActionPerformed

 
    private void btdangxuatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btdangxuatActionPerformed
        // TODO add your handling code here:
        PNqldg.setVisible(false);
        PNqls.setVisible(false);
        PNms.setVisible(false);
        PNts.setVisible(false);
        btdangxuat.setVisible(false);
        btdangnhap.setVisible(true);
}//GEN-LAST:event_btdangxuatActionPerformed

    /*************************
    //quan ly sach
     *************************
     */
   
    public void loadcbqls()
    {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            try {
                Connection con = DriverManager.getConnection(getURLConnection());
                Statement stm = con.createStatement();               
                ResultSet rs1 = stm.executeQuery("SELECT* FROM TACGIA");
                while(rs1.next())
                {
                    String hoten= rs1.getString("HOTEN");
                    cb_qls_tacgia.addItem(hoten);
                }

                ResultSet rs2=stm.executeQuery("SELECT * FROM NGONNGU");
                while(rs2.next())
                {
                    String ngonngu= rs2.getString("NGONNGU");
                    cb_qls_ngonngu.addItem(ngonngu);
                }

                ResultSet rs3=stm.executeQuery("SELECT *FROM LOAISACH");
                while(rs3.next())
                {
                    String linhvuc= rs3.getString("TENLOAISACH");
                    cb_qls_linhvuc.addItem(linhvuc);
                }

                ResultSet rs4=stm.executeQuery("SELECT *FROM NXB");
                while(rs4.next())
                {
                    String nxb= rs4.getString("TENNXB");
                    cb_qls_nhaxuatban.addItem(nxb);
                }

                ResultSet rs5=stm.executeQuery("SELECT *FROM NHACUNGCAP");
                while(rs5.next())
                {
                    String ncc= rs5.getString("TENNCC");
                    cb_qls_nhacungcap.addItem(ncc);
                }

            } 
            catch (SQLException ex) {
                Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
            }
        } 
        catch (ClassNotFoundException ex) {
            Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
        }
        //dua du lieu vao combox

    }


    public void clearqls()
    {
        tb_qls_masach.setText("");
        tb_qls_gia.setText("");
        tb_qls_tensach.setText("");
        cb_qls_linhvuc.removeAllItems();
        cb_qls_tacgia.removeAllItems();
        cb_qls_ngonngu.removeAllItems();
        cb_qls_nhaxuatban.removeAllItems();
        cb_qls_nhacungcap.removeAllItems();
    }

    public void openboxqls()
    {
        tb_qls_masach.setVisible(true);
        tb_qls_tensach.setVisible(true);
        tb_qls_gia.setVisible(true);
        cb_qls_linhvuc.setVisible(true);
        cb_qls_tacgia.setVisible(true);
        cb_qls_nhacungcap.setVisible(true);
        cb_qls_nhaxuatban.setVisible(true);
        cb_qls_ngonngu.setVisible(true);

    }

    public void closeboxqls()
    {
        tb_qls_masach.setVisible(false);
        tb_qls_tensach.setVisible(false);
        tb_qls_gia.setVisible(false);
        cb_qls_linhvuc.setVisible(false);
        cb_qls_tacgia.setVisible(false);
        cb_qls_nhacungcap.setVisible(false);
        cb_qls_nhaxuatban.setVisible(false);
        cb_qls_ngonngu.setVisible(false);
    }
    
    private void bt_qls_themActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_qls_themActionPerformed
        //sua cai button cho giong C#
        if(bt_qls_them.getText().equals("Thêm"))
        {
            openboxqls();
            loadcbqls();
            bt_qls_them.setText("Chấp Nhận");
            bt_qls_sua.setVisible(false);
            bt_qls_xoa.setVisible(false);
        }
        else if(bt_qls_them.getText().equals("Chấp Nhận"))
        {
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                try {
                    Connection con = DriverManager.getConnection(getURLConnection());
                    lop_sach l_sach = new lop_sach();
                    int gia=Integer.parseInt(tb_qls_gia.getText());
                    
                    // lay du lieu tu combox
                    String maloai = cb_qls_linhvuc.getSelectedItem().toString();
                    String manxb = cb_qls_nhaxuatban.getSelectedItem().toString();
                    String mancc = cb_qls_nhacungcap.getSelectedItem().toString();
                    String matg = cb_qls_tacgia.getSelectedItem().toString();
                    String mann = cb_qls_ngonngu.getSelectedItem().toString();
                    Statement stm = con.createStatement();                    
                    ResultSet rs1=stm.executeQuery("SELECT *FROM NXB WHERE TENNXB='"+manxb+"'");                  
                    while(rs1.next())
                    {
                        String nxb= rs1.getString("MANXB");
                        l_sach.set_manhaxuatban(nxb);
                    }
                    ResultSet rs2=stm.executeQuery("SELECT *FROM NHACUNGCAP WHERE TENNCC='"+mancc+"'");
                    while(rs2.next())
                    {
                        String ncc= rs2.getString("MANCC");
                        l_sach.set_mancc(ncc);
                    }
                    ResultSet rs3=stm.executeQuery("SELECT *FROM TACGIA WHERE HOTEN='"+matg+"'");
                    while(rs3.next())
                    {
                        String tg= rs3.getString("MATACGIA");
                        l_sach.set_matacgia(tg);
                    }
                    ResultSet rs4=stm.executeQuery("SELECT *FROM NGONNGU WHERE NGONNGU='"+mann+"'");
                    while(rs4.next())
                    {
                        String nn= rs4.getString("MANGONNGU");
                        l_sach.set_mangonngu(nn);
                    }
                    ResultSet rs5=stm.executeQuery("SELECT *FROM LOAISACH WHERE TENLOAISACH='"+maloai+"'");
                    while(rs5.next())
                    {
                        String loai= rs5.getString("MALOAISACH");
                        l_sach.set_maloai(loai);
                    }                    
                    
                    l_sach.set_gia(gia);
                    l_sach.set_masach(tb_qls_masach.getText());
                    l_sach.set_tensach(tb_qls_tensach.getText());
                    if(l_sach.taosachmoi())
                    {
                        if(l_sach.taomoisangtac())
                        JOptionPane.showMessageDialog(this,"cap nhat thanh cong");
                        else JOptionPane.showMessageDialog(this, "ko cap nhat duoc sang tac");
                    }
                    else
                        JOptionPane.showMessageDialog(this, "ko thanh cong");
                    clearqls();
                    bt_qls_them.setText("Thêm");
                    closeboxqls();
                    bt_qls_sua.setVisible(true);
                    bt_qls_xoa.setVisible(true);

                } catch (SQLException ex) {
                    Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
            }            
        }
    }//GEN-LAST:event_bt_qls_themActionPerformed

    private void cb_qls_linhvucActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_qls_linhvucActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cb_qls_linhvucActionPerformed

    boolean kt=false;
    private void bt_qls_suaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_qls_suaActionPerformed
        // TODO add your handling code here:
        if (bt_qls_sua.getText().equals("Sữa"))
        {
            tb_qls_masach.setVisible(true);            
            JOptionPane.showMessageDialog(this, "Nhập vào mã sách cần sữa");
            tb_qls_masach.setText("nhap ma sach");
            bt_qls_sua.setText("Xác Nhận");
            bt_qls_them.setVisible(false);
            bt_qls_xoa.setVisible(false);
        }
        else if(bt_qls_sua.getText().equals("Xác Nhận"))
        {
             try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                try {
                    Connection con = DriverManager.getConnection(getURLConnection());
                    Statement stm = con.createStatement();
                    ResultSet rs= stm.executeQuery("SELECT *FROM SACH");                    
                    String masach=tb_qls_masach.getText().toUpperCase();
                    while(rs.next())
                    {
                        if(rs.getString("MASACH").trim().equals(masach))
                        kt=true;
                    }
                    if(kt)
                    {                        
                        openboxqls();
                        ResultSet rs1 = stm.executeQuery("select GIA,TENSACH,TENLOAISACH,HOTEN,NGONNGU,TENNXB,TENNCC from SACH,LOAISACH,NGONNGU,NXB,TACGIA,SANGTAC,NHACUNGCAP where SACH.MASACH='" + masach + "' AND SACH.MANGONNGU=NGONNGU.MANGONNGU AND SACH.MALOAISACH=LOAISACH.MALOAISACH AND SACH.MANCC=NHACUNGCAP.MANCC AND SACH.MANXB=NXB.MANXB AND SACH.MASACH=SANGTAC.MASACH AND TACGIA.MATACGIA=SANGTAC.MATACGIA ");
                        while(rs1.next())
                        {                            
                            String gia=""+rs1.getInt("gia");
                            tb_qls_gia.setText(gia);                            
                            tb_qls_tensach.setText(rs1.getString("TENSACH"));
                            cb_qls_linhvuc.addItem(rs1.getString("TENLOAISACH"));
                            cb_qls_tacgia.addItem(rs1.getString("HOTEN"));
                            cb_qls_ngonngu.addItem(rs1.getString("NGONNGU"));
                            cb_qls_nhaxuatban.addItem(rs1.getString("TENNXB"));
                            cb_qls_nhacungcap.addItem(rs1.getString("TENNCC"));
                        }
                        loadcbqls();
                        // tim cac du lieu trung trong cb de xoa
                        bt_qls_sua.setText("Chấp Nhận");
                        kt=false;
                    }
                    else JOptionPane.showMessageDialog(this,"Bạn phải nhập đúng mã sách ");
              } catch (SQLException ex) {
                    Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        else if(bt_qls_sua.getText().equals("Chấp Nhận"))
        {
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                try {
                    Connection con = DriverManager.getConnection(getURLConnection());
                    lop_sach l_sach = new lop_sach();
                    int gia=Integer.parseInt(tb_qls_gia.getText());

                    // lay du lieu tu combox
                    String maloai = cb_qls_linhvuc.getSelectedItem().toString();
                    String manxb = cb_qls_nhaxuatban.getSelectedItem().toString();
                    String mancc = cb_qls_nhacungcap.getSelectedItem().toString();
                    String matg = cb_qls_tacgia.getSelectedItem().toString();
                    String mann = cb_qls_ngonngu.getSelectedItem().toString();
                    Statement stm = con.createStatement();
                    ResultSet rs1=stm.executeQuery("SELECT *FROM NXB WHERE TENNXB='"+manxb+"'");
                    while(rs1.next())
                    {
                        String nxb= rs1.getString("MANXB");
                        l_sach.set_manhaxuatban(nxb);
                    }
                    ResultSet rs2=stm.executeQuery("SELECT *FROM NHACUNGCAP WHERE TENNCC='"+mancc+"'");
                    while(rs2.next())
                    {
                        String ncc= rs2.getString("MANCC");
                        l_sach.set_mancc(ncc);
                    }
                    ResultSet rs3=stm.executeQuery("SELECT *FROM TACGIA WHERE HOTEN='"+matg+"'");
                    while(rs3.next())
                    {
                        String tg= rs3.getString("MATACGIA");
                        l_sach.set_matacgia(tg);
                    }
                    ResultSet rs4=stm.executeQuery("SELECT *FROM NGONNGU WHERE NGONNGU='"+mann+"'");
                    while(rs4.next())
                    {
                        String nn= rs4.getString("MANGONNGU");
                        l_sach.set_mangonngu(nn);
                    }
                    ResultSet rs5=stm.executeQuery("SELECT *FROM LOAISACH WHERE TENLOAISACH='"+maloai+"'");
                    while(rs5.next())
                    {
                        String loai= rs5.getString("MALOAISACH");
                        l_sach.set_maloai(loai);
                    }

                    l_sach.set_gia(gia);
                    l_sach.set_masach(tb_qls_masach.getText());
                    l_sach.set_tensach(tb_qls_tensach.getText());
                    if(l_sach.suasach())
                    {
                        if(l_sach.suasangtac())
                        JOptionPane.showMessageDialog(this,"cap nhat thanh cong");
                        else JOptionPane.showMessageDialog(this, "ko cap nhat duoc sang tac");
                    }
                    else
                        JOptionPane.showMessageDialog(this, "ko thanh cong");
                    clearqls();
                    bt_qls_sua.setText("Sữa");
                    closeboxqls();
                    bt_qls_them.setVisible(true);
                    bt_qls_xoa.setVisible(true);
                    
                } catch (SQLException ex) {
                    Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
            }            
        }
        

    }//GEN-LAST:event_bt_qls_suaActionPerformed

    private void bt_qls_xoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_qls_xoaActionPerformed
        // TODO add your handling code here:
        if (bt_qls_xoa.getText().equals("Xóa"))
        {
            tb_qls_masach.setVisible(true);
            JOptionPane.showMessageDialog(this, "Nhập vào mã sách cần Xóa");
            tb_qls_masach.setText("nhap ma sach");
            bt_qls_xoa.setText("Xác Nhận");
            bt_qls_them.setVisible(false);
            bt_qls_sua.setVisible(false);
        }
        else if(bt_qls_xoa.getText().equals("Xác Nhận"))
        {
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                try {
                    Connection con = DriverManager.getConnection(getURLConnection());
                    Statement stm = con.createStatement();
                    ResultSet rs= stm.executeQuery("SELECT *FROM SACH");
                    String masach=tb_qls_masach.getText().toUpperCase();
                    while(rs.next())
                    {
                        if(rs.getString("MASACH").trim().equals(masach))
                        kt=true;
                    }
                    if(kt)
                    {
                        openboxqls();
                        ResultSet rs1 = stm.executeQuery("select GIA,TENSACH,TENLOAISACH,HOTEN,NGONNGU,TENNXB,TENNCC from SACH,LOAISACH,NGONNGU,NXB,TACGIA,SANGTAC,NHACUNGCAP where SACH.MASACH='" + masach + "' AND SACH.MANGONNGU=NGONNGU.MANGONNGU AND SACH.MALOAISACH=LOAISACH.MALOAISACH AND SACH.MANCC=NHACUNGCAP.MANCC AND SACH.MANXB=NXB.MANXB AND SACH.MASACH=SANGTAC.MASACH AND TACGIA.MATACGIA=SANGTAC.MATACGIA ");
                        while(rs1.next())
                        {
                            String gia=""+rs1.getInt("gia");
                            tb_qls_gia.setText(gia);
                            tb_qls_tensach.setText(rs1.getString("TENSACH"));
                            cb_qls_linhvuc.addItem(rs1.getString("TENLOAISACH"));
                            cb_qls_tacgia.addItem(rs1.getString("HOTEN"));
                            cb_qls_ngonngu.addItem(rs1.getString("NGONNGU"));
                            cb_qls_nhaxuatban.addItem(rs1.getString("TENNXB"));
                            cb_qls_nhacungcap.addItem(rs1.getString("TENNCC"));
                        }
                        loadcbqls();
                        // tim cac du lieu trung trong cb de xoa
                        bt_qls_xoa.setText("Chấp Nhận");
                        kt=false;
                    }
                    else JOptionPane.showMessageDialog(this,"Bạn phải nhập đúng mã sách ");
              } catch (SQLException ex) {
                    Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        else if(bt_qls_xoa.getText().equals("Chấp Nhận"))
        {
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                try {
                    Connection con = DriverManager.getConnection(getURLConnection());
                    lop_sach l_sach = new lop_sach();
                    String masach=tb_qls_masach.getText();
                    l_sach.set_masach(masach);
                    if(l_sach.xoasangtac())
                    {
                        if(l_sach.xoasach())
                        JOptionPane.showMessageDialog(this,"cap nhat thanh cong");
                        else JOptionPane.showMessageDialog(this, "ko cap nhat duoc sach");
                    }
                    else
                        JOptionPane.showMessageDialog(this, "ko thanh cong");
                    clearqls();
                    bt_qls_xoa.setText("Xóa");
                    closeboxqls();
                    bt_qls_them.setVisible(true);
                    bt_qls_sua.setVisible(true);
                    } catch (SQLException ex) {
                    Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_bt_qls_xoaActionPerformed

    /*************************
    //quan ly muon sach
     *************************
     */

    boolean ktdg=false;
    boolean kts=false;
    String ngaymuon = "",ngayhethantra="",phieutam;
     public void loadqlms()
    {
        bt_qlms_ktsach.setVisible(false);
        tb_qlms_mas.setVisible(false);
        bt_qlms_chomuon.setVisible(false);
    }
    
    public void cleartextbandoc()
    {
        tb_qlms_hoten.setText("");
        tb_qlms_doituong.setText("");
        tb_qlms_diachi.setText("");
        tb_qlms_ngaysinh.setText("");
        tb_qlms_gioitinh.setText("");
        tb_qlms_mapm.setText("");
        tb_qlms_ngayhethan.setText("");
    }

    public void cleartextsach()
    {
        tb_qlms_tensach.setText("");
        tb_qlms_tacgia.setText("");
        tb_qlms_linhvuc.setText("");
        tb_qlms_gia.setText("");
        tb_qlms_ngonngu.setText("");
        tb_qlms_nhaxuatban.setText("");
    }

    public void layphieumuon()
    {
        phieutam="";
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            try {
                Connection con = DriverManager.getConnection(getURLConnection());
                Statement stm=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                     ResultSet.CONCUR_READ_ONLY);
                ResultSet rs=stm.executeQuery("SELECT maphieu FROM phieumuon");
                rs.last();
                String s = rs.getString("maphieu");
                phieutam=s;
                s=s.substring(2,6);
                int i=Integer.parseInt(s);
                i++;
                if (phieutam.equals("")) { phieutam = "PM0001"; }
                else
                {
                    if (i < 10)
                    {
                        s = "PM000" + i;
                    }
                    else if (i < 100)
                    {
                        s = "PM00" + i;
                    }
                    else if (i < 1000)
                    {
                        s = "PM0" + i;
                    }
                    else if (i < 10000)
                    {
                        s = "PM" + i;
                    }
                    phieutam = s;
                }
                tb_qlms_mapm.setText(phieutam);
                tb_qlms_mas.setText("nhập mã sách");
                tb_qlms_madg.setVisible(true);
                
            } catch (SQLException ex) {
                Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
   
    String ngayhethan;
    //ngay thang nam hien tai va het han
    int monthhh, dayhh, yearhh, month, year, day;
    int sltoida=0, soluongmuon = 0;

    public void muontoida()
    {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            try {
                Connection con = DriverManager.getConnection(getURLConnection());
                Statement stm= con.createStatement();
                ResultSet rs=stm.executeQuery("select SOLUONGMUONTOIDA FROM DOCGIA,LOAIDOCGIA WHERE DOCGIA.MADOCGIA='" + tb_qlms_madg.getText() + "' AND DOCGIA.MALOAIDOCGIA=LOAIDOCGIA.MALOAIDOCGIA");
                while(rs.next())
                {
                    sltoida=rs.getInt("SOLUONGMUONTOIDA");                 
                }                
            } catch (SQLException ex) {
                Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
    private void bt_qlms_ktdgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_qlms_ktdgActionPerformed
        // TODO add your handling code here:
        cleartextbandoc();
        bt_qlms_chomuon.setVisible(false);
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            try {
                Connection con = DriverManager.getConnection(getURLConnection());
                Statement stm=con.createStatement();
                ResultSet rs = stm.executeQuery("SELECT HOTEN,DIACHI,GIOITINH,TENLOAIDG,NGAYSINH FROM DOCGIA,LOAIDOCGIA WHERE DOCGIA.MADOCGIA='" + tb_qlms_madg.getText() + "' AND DOCGIA.MALOAIDOCGIA=LOAIDOCGIA.MALOAIDOCGIA");
                while(rs.next())
                {
                    tb_qlms_hoten.setText(rs.getString("HOTEN"));
                    tb_qlms_diachi.setText(rs.getString("DIACHI"));
                    tb_qlms_gioitinh.setText(rs.getString("GIOITINH"));
                    tb_qlms_doituong.setText(rs.getString("TENLOAIDG"));
                    Date date= rs.getDate("NGAYSINH");
                    String s=""+date;
                    tb_qlms_ngaysinh.setText(s);
                    ktdg=true;
                }

                if(tb_qlms_hoten.equals(""))
                {
                    JOptionPane.showMessageDialog(this, "ko tồn tại");
                }
                else
                {
                    Calendar c=Calendar.getInstance();
                    day=c.get(Calendar.DAY_OF_MONTH);
                    month=c.get(Calendar.MONTH);
                    year =c.get(Calendar.YEAR);
                    ResultSet rs1=stm.executeQuery("select ngayhethan from The where The.MADOCGIA='" +tb_qlms_madg.getText() + "'");
                    while(rs1.next())
                    {
                        ngayhethan=rs1.getString("ngayhethan");
                        tb_qlms_ngayhethan.setText(ngayhethan);
                    }
                    yearhh=Integer.parseInt(ngayhethan.substring(0,4));
                    monthhh=Integer.parseInt(ngayhethan.substring(5,7));
                    dayhh=Integer.parseInt(ngayhethan.substring(8,10));                                                
                    if (year > yearhh)
                    {
                        JOptionPane.showMessageDialog(this, "Thẻ đã hết hạn sử dụng");
                        tb_qlms_mas.setVisible(false);
                        tb_qlms_mapm.setText("");
                        bt_qlms_chomuon.setVisible(false);
                    }
                    else if (year == yearhh)
                    {
                        if (month > monthhh)
                        {
                            JOptionPane.showMessageDialog(this, "Thẻ đã hết hạn sử dụng");
                            tb_qlms_mas.setVisible(false);
                            tb_qlms_mapm.setText("");
                            bt_qlms_chomuon.setVisible(false);
                        }
                        else if (month == monthhh)
                        {
                            if (day > dayhh)
                            {
                                JOptionPane.showMessageDialog(this, "Thẻ đã hết hạn sử dụng");
                                tb_qlms_mas.setVisible(false);
                                tb_qlms_mapm.setText("");
                                bt_qlms_chomuon.setVisible(false);
                            }
                        }
                        else
                        {
                            monthhh = monthhh + 3;
                            if (dayhh > 30)
                            {
                                monthhh = monthhh + 1;
                                dayhh = dayhh - 30;
                            }
                            if (monthhh > 12 || monthhh + 3 > 12)
                            {
                                monthhh = monthhh - 12;
                                year += 1;
                            }
                            if (year > yearhh)
                            {
                                JOptionPane.showMessageDialog(this, "Thẻ sắp hết hạn sử dụng");
                                layphieumuon();
                            }
                            else if (year == yearhh)
                            {
                                if (month > monthhh)
                                {
                                    JOptionPane.showMessageDialog(this, "Thẻ sắp hết hạn sử dụng");
                                    layphieumuon();
                                }
                                else if (month == monthhh)
                                {
                                    if (day > dayhh)
                                    {
                                        JOptionPane.showMessageDialog(this, "Thẻ sắp hết hạn sử dụng");
                                        layphieumuon();
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        layphieumuon();
                    }
                }
                bt_qlms_ktdg.setVisible(false);
                tb_qlms_madg.setVisible(false);
                bt_qlms_ktsach.setVisible(true);
                tb_qlms_mas.setVisible(true);     
            } catch (SQLException ex) {
                Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
            }

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
        }        
    }//GEN-LAST:event_bt_qlms_ktdgActionPerformed

    private void bt_qlms_ktsachActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_qlms_ktsachActionPerformed
        // TODO add your handling code here:
        cleartextsach();
        bt_qlms_chomuon.setVisible(true);
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            try {
                Connection con = DriverManager.getConnection(getURLConnection());
                Statement stm=con.createStatement();
                ResultSet rs=stm.executeQuery("select TENSACH,HOTEN,TENLOAISACH,NGONNGU,GIA,TENNXB from SACH,LOAISACH,NGONNGU,NXB,TACGIA,SANGTAC where SACH.MASACH='" + tb_qlms_mas.getText() + "' AND SACH.MANGONNGU=NGONNGU.MANGONNGU AND SACH.MALOAISACH=LOAISACH.MALOAISACH AND SACH.MANXB=NXB.MANXB AND SACH.MASACH=SANGTAC.MASACH AND TACGIA.MATACGIA=SANGTAC.MATACGIA");
                while(rs.next())
                {
                    tb_qlms_tensach.setText(rs.getString("TENSACH"));
                    tb_qlms_tacgia.setText(rs.getString("HOTEN"));
                    tb_qlms_linhvuc.setText(rs.getString("TENLOAISACH"));
                    tb_qlms_ngonngu.setText(rs.getString("NGONNGU"));
                    int i=rs.getInt("GIA");
                    tb_qlms_gia.setText(""+i);
                    tb_qlms_nhaxuatban.setText(rs.getString("TENNXB"));
                    kts=true;
                }
                if(tb_qlms_tensach.equals(""))
                {
                    JOptionPane.showMessageDialog(this, "Không Tồn tại");
                }

                else
                {
                    boolean sach=false;
                    String masach="";
                    ResultSet rs1=stm.executeQuery("SELECT SACH.masach FROM SACH,PHIEUMUON,SACH_PHIEU WHERE PHIEUMUON.MAPHIEU=SACH_PHIEU.MAPHIEU AND SACH_PHIEU.MASACH=SACH.MASACH AND SACH_PHIEU.NGAYTRA IS NULL");
                    while(rs1.next())
                    {
                        masach=rs1.getString("MASACH");
                        if(masach.trim().equals(tb_qlms_mas.getText()))
                        {
                            sach=true;
                        }
                    }

                    if(sach)
                    {
                        JOptionPane.showMessageDialog(this, "Sách này đã cho mượn");
                        bt_qlms_chomuon.setVisible(false);
                    }
                }               


                } catch (SQLException ex) {
                Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
            }

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_bt_qlms_ktsachActionPerformed

    boolean taopm=true;
    private void bt_qlms_chomuonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_qlms_chomuonActionPerformed
        // TODO add your handling code here:
        if(ktdg&&kts)
        {
            Calendar c=Calendar.getInstance();
            ngaymuon=""+c.get(Calendar.MONTH)+"/"+c.get(Calendar.DAY_OF_MONTH)+"/"+c.get(Calendar.YEAR);
            int i=0;
            //tb_qlms_linhvuc.setText(ngaymuon);
            
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                try {
                    Connection con = DriverManager.getConnection(getURLConnection());
                    Statement stm=con.createStatement();
                    //dua vao ten doc gia xem cac sach muon truoc do
                    ResultSet rs=stm.executeQuery("SELECT SACH.MASACH FROM SACH,DOCGIA,PHIEUMUON,SACH_PHIEU WHERE DOCGIA.MADOCGIA='"+tb_qlms_madg.getText()+"' AND DOCGIA.MADOCGIA=PHIEUMUON.MADOCGIA AND PHIEUMUON.MAPHIEU=SACH_PHIEU.MAPHIEU AND SACH_PHIEU.MASACH=SACH.MASACH AND SACH_PHIEU.NGAYTRA IS NULL");
                    while(rs.next())
                    {
                        //ko lay duoc kq
                        i++;
                    }
                    soluongmuon = i;
                    muontoida();                   
                    if (soluongmuon == sltoida)
                    JOptionPane.showMessageDialog(this, "Số lượng mượn đã tối đa");
                    else
                    {
                        //cho muon tung quyen sach
                        ResultSet rs1=stm.executeQuery("SELECT MAPHIEU FROM DOCGIA,PHIEUMUON WHERE DOCGIA.MADOCGIA='" + tb_qlms_madg.getText() + "' AND DOCGIA.MADOCGIA=PHIEUMUON.MADOCGIA");
                        while(rs1.next())
                        {
                            if(phieutam.equals(rs1.getString("MAPHIEU").trim()))
                            taopm = false;
                        }
                        if(taopm)
                        {
                            phieumuon pm = new phieumuon();
                            pm.set_maPM(tb_qlms_mapm.getText());
                            pm.set_madg(tb_qlms_madg.getText());
                            pm.set_manv(manhanvien);
                            //Date ngaymuon1=Date.valueOf(ngaymuon);
                            pm.set_ngaymuon(ngaymuon);
                            if(pm.taomoiphieumuon())
                            {
                           
                            }
                            else JOptionPane.showMessageDialog(this, "có lỗi không tạo được phiếu mượn");
                        }                        
                        int daytra = c.get(Calendar.DAY_OF_MONTH);
                        int monthtra = c.get(Calendar.MONTH);
                        int yeartra = c.get(Calendar.YEAR);
                        if (monthtra + 3 > 12)
                        {
                            monthtra = monthtra + 3 - 12;
                            yeartra += 1;
                        }
                        else monthtra += 3;
                        ngayhethantra = "" + monthtra + "/" + daytra + "/" + yeartra;
                        //Date ngayhh = Date.valueOf(ngayhethantra);
                        phieusach ps = new phieusach();
                        ps.set_maphieumuon(tb_qlms_mapm.getText());
                        ps.set_masach(tb_qlms_mas.getText());
                        ps.set_ngayhethantra(ngayhethantra);
                        if (ps.taomoiphieusach())
                        {
                            soluongmuon++;
                            JOptionPane.showMessageDialog(this, "Đã cho mượn sách ");
                        }
                        else
                        JOptionPane.showMessageDialog(this, "có lỗi ko tạo được phiếu sách");                       
                    }

                } catch (SQLException ex) {
                    Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
                }

            } catch (ClassNotFoundException ex) {
                Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
                
            }
        }
        else
        JOptionPane.showMessageDialog(this, "Phải kiểm tra thông tin trước khi cho mượn");
        bt_qlms_chomuon.setVisible(false);
    }//GEN-LAST:event_bt_qlms_chomuonActionPerformed

    private void bt_qlms_huythaotacActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_qlms_huythaotacActionPerformed
        // TODO add your handling code here:
        tb_qlms_madg.setText("");
        tb_qlms_hoten.setText("");
        tb_qlms_doituong.setText("");
        tb_qlms_diachi.setText("");
        tb_qlms_ngaysinh.setText("");
        tb_qlms_gioitinh.setText("");
        tb_qlms_ngayhethan.setText("");
        tb_qlms_mapm.setText("");
        tb_qlms_mas.setText("");
        tb_qlms_tensach.setText("");
        tb_qlms_tacgia.setText("");
        tb_qlms_linhvuc.setText("");
        tb_qlms_ngonngu.setText("");
        tb_qlms_gia.setText("");
        tb_qlms_nhaxuatban.setText("");
        ktdg = false;
        kts = false;
        bt_qlms_chomuon.setVisible(false);
        bt_qlms_ktsach.setVisible(false);
        tb_qlms_mas.setVisible(false);
        bt_qlms_ktdg.setVisible(true);
        tb_qlms_madg.setVisible(true);
         
    }//GEN-LAST:event_bt_qlms_huythaotacActionPerformed

     /*************************
    //quan ly tra sach
     *************************
     */
    int sosachmuon;


    public void loadqlts()
    {
        tb_qlts_mas.setVisible(false);
        tb_qlts_songayquahan.setVisible(false);
        tb_qlts_xuphat.setVisible(false);
        cb_qlts_matsach.setVisible(false);
        bt_qlts_kts.setVisible(false);
        bt_qlts_ts.setVisible(false);
    }

    private void bt_qlts_ktdgActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_qlts_ktdgActionPerformed
        // TODO add your handling code here:
        //tb_xemkq.removeAll();
        //tb_xemkq.removeEditor();
        int i=0;
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            try {
                Connection con = DriverManager.getConnection(getURLConnection());
                Statement stm =con.createStatement();
                ResultSet rs=stm.executeQuery("SELECT DOCGIA.HOTEN FROM DOCGIA,PHIEUMUON,SACH_PHIEU,SACH WHERE DOCGIA.MADOCGIA='" + tb_qlts_madg.getText() + "' AND DOCGIA.MADOCGIA=PHIEUMUON.MADOCGIA AND PHIEUMUON.MAPHIEU=SACH_PHIEU.MAPHIEU AND SACH_PHIEU.MASACH = SACH.MASACH AND SACH_PHIEU.NGAYTRA IS NULL");
                while(rs.next())
                {
                    tb_qlts_tendg.setText(rs.getString("HOTEN"));
                    i++;
                }
                tb_qlts_sosachmuon.setText(""+i);
                sosachmuon = i;
                tb_qlts_mas.setText("nhập mã sách");
                loadtb_qlts();
                tb_qlts_mas.setVisible(true);
                tb_qlts_madg.setVisible(false);
                bt_qlts_ts.setVisible(true);
                bt_qlts_ktdg.setVisible(false);
                bt_qlts_kts.setVisible(true);
                tb_qlts_xuphat.setVisible(true);
                tb_qlts_songayquahan.setVisible(true);
                
            } catch (SQLException ex) {
                Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
            }

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_bt_qlts_ktdgActionPerformed

    String ngaymuonts;
    int monthm, daym, yearm;
    int songayquahan=0;
    private void bt_qlts_ktsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_qlts_ktsActionPerformed
        // TODO add your handling code here:
        Calendar c = Calendar.getInstance();
        int monthts = c.get(Calendar.MONTH)+1; //KO HIEU LY DO NO LAY THIEU 1 THANG TRONG THANG HE THONG
        int dayts = c.get(Calendar.DAY_OF_MONTH);
        int yearts = c.get(Calendar.YEAR);
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            try {
                Connection con = DriverManager.getConnection(getURLConnection());
                Statement stm =con.createStatement();
                ResultSet rs=stm.executeQuery("SELECT  NGAYHETHANTRA FROM SACH_PHIEU,SACH WHERE SACH.MASACH='" + tb_qlts_mas.getText() + "' AND SACH_PHIEU.MASACH = SACH.MASACH AND SACH_PHIEU.NGAYTRA IS NULL");
                while(rs.next())
                {
                    ngaymuonts=""+rs.getDate("NGAYHETHANTRA");
                    //ngaymuon=Convert.ToString(dr["NGAYHETHANTRA"]);
                }
                //tb_qlts_songayquahan.setText(ngaymuon);
                yearm=Integer.parseInt(ngaymuonts.substring(0, 4));
                monthm=Integer.parseInt(ngaymuonts.substring(5,7));
                daym=Integer.parseInt(ngaymuonts.substring(8,10));                
                songayquahan=monthts - monthm;
                songayquahan = (yearts - yearm) * 365 + (monthts - monthm) * 30 + (dayts - daym);
                if (songayquahan < 0)
                    songayquahan = 0;
                //SO NGAY QUA HAN KO NHA                
                tb_qlts_songayquahan.setText(""+songayquahan);
                bt_qlts_ts.setVisible(true);                
                
            } catch (SQLException ex) {
                Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
            }

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
    }//GEN-LAST:event_bt_qlts_ktsActionPerformed

    String maphieu = "";
    int tienphat,giasach;
    boolean matsach = false;
    private void bt_qlts_tsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_qlts_tsActionPerformed
        // TODO add your handling code here:
      
        String xuphat;
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            try {
                Connection con = DriverManager.getConnection(getURLConnection());
                Statement stm =con.createStatement();
                ResultSet rs = stm.executeQuery("SELECT PHIEUMUON.MAPHIEU,SACH.GIA FROM SACH,DOCGIA,PHIEUMUON,SACH_PHIEU WHERE DOCGIA.MADOCGIA='" + tb_qlts_madg.getText() + "' AND SACH.MASACH='"+ tb_qlts_mas.getText() + "' AND DOCGIA.MADOCGIA=PHIEUMUON.MADOCGIA AND PHIEUMUON.MAPHIEU=SACH_PHIEU.MAPHIEU AND SACH_PHIEU.MASACH=SACH.MASACH AND SACH_PHIEU.NGAYTRA IS NULL");
                while(rs.next())
                {
                    maphieu = rs.getString("MAPHIEU");
                    giasach=rs.getInt("gia");
                }
                if(cb_qlts_matsach.isSelected())
                {
                    xuphat = "MATSACH";
                    matsach = true;
                }
                else if (songayquahan > 0)
                {
                    xuphat = "TREHAN";
                }
                else xuphat = "";
                
                ResultSet rs1=stm.executeQuery("SELECT THAMSOXUPHAT.MUCPHAT FROM THAMSOXUPHAT WHERE THAMSOXUPHAT.TENXUPHAT='"+xuphat+ "'");
                while(rs1.next())
                {
                    tienphat=rs1.getInt("MUCPHAT");
                }
                int mucphat = tienphat;
                
                if (xuphat.equals("MATSACH"))
                {
                    tienphat = tienphat * giasach;
                }
                else if(xuphat.equals("TREHAN"))
                tienphat = tienphat * songayquahan;
                Calendar c = Calendar.getInstance();
                int mon=c.get(Calendar.MONTH)+1;
                String today = ""+ mon +"/"+c.get(Calendar.DAY_OF_MONTH)+"/"+c.get(Calendar.YEAR);
                phieusach ps = new phieusach();
                ps.set_maphieumuon(maphieu);
                ps.set_matsach(matsach);
                ps.set_ngaytra(today);
                ps.set_songayquahan(songayquahan);
                ps.set_tienphat(tienphat);
                ps.set_masach(tb_qlts_mas.getText());                          
                
                
                if (ps.trasach())
                {
                    if(matsach==true)
                    {
                        JOptionPane.showMessageDialog(this, "Độc giả phải đền gấp "+mucphat+" lần giá trị quyển sách");
                        //MessageBox.Show("Độc giả phải đền gấp "+mucphat+" lần giá trị quyển sách", "Thông Báo");
                        sosachmuon--;
                        tb_qlts_xuphat.setText(""+ps.get_tienphat());
                        //tbxuphat.Text = Convert.ToString(ps.get_tienphat());
                    }
                    else if (songayquahan > 0)
                    {
                        JOptionPane.showMessageDialog(this, "Độc giả đã trả sách trễ hạn " + songayquahan + " ngày");
                        //MessageBox.Show("Độc giả đã trả sách trễ hạn " + songayquahan + " ngày", "Thông Báo");
                        sosachmuon--;
                        tb_qlts_xuphat.setText(""+ps.get_tienphat());
                    }
                    else
                    {
                        JOptionPane.showMessageDialog(this, "Đã trả sách thành công");
                        //MessageBox.Show("Đã trả sách thành công", "Thông Báo");
                        sosachmuon--;
                        tb_qlts_sosachmuon.setText(""+sosachmuon);
                    }
                }  
                else     JOptionPane.showMessageDialog(this, "Có lỗi ko update được phiếu mượn");

                 
            } catch (SQLException ex) {
                Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
            }

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_bt_qlts_tsActionPerformed

    private void bt_qlts_huythaotacActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_qlts_huythaotacActionPerformed
        // TODO add your handling code here:
        tb_qlts_madg.setText("");
        tb_qlts_mas.setText("");
        tb_qlts_sosachmuon.setText("");
        tb_qlts_tendg.setText("");
        tb_qlts_songayquahan.setText("");
        tb_qlts_xuphat.setText("");
        cb_qlts_matsach.setSelected(false);
        tb_qlts_madg.setVisible(true);
        bt_qlts_ktdg.setVisible(true);
        tb_qlts_mas.setVisible(false);
        bt_qlts_ts.setVisible(false);
        bt_qlts_kts.setVisible(false);
        tb_qlts_songayquahan.setVisible(false);
        tb_qlts_xuphat.setVisible(false);
          for(int i=0;i<5;i++)
                    {
                        tb_xemkq.setValueAt("", i, 0);
                        tb_xemkq.setValueAt("", i, 1);
                        tb_xemkq.setValueAt("", i, 2);
                    }
    }//GEN-LAST:event_bt_qlts_huythaotacActionPerformed

    /*************************
    //quan ly doc gia
     *************************
     */
    Connection con1=null;
    Statement stmt1, stmt2;
    Vector column, data;
    DefaultTableModel modelDG = new DefaultTableModel(data,column);
      public void SetModel(){
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            con1 = DriverManager.getConnection(getURLConnection());

            SimpleDateFormat formatDate = new SimpleDateFormat("dd-MM-yyyy");
            table_DOCGIA.setModel(modelDG); //Sets the data model for this table to newModel and registers
            stmt2 = con1.createStatement();
            data = new Vector();
            column = new Vector();

            //Add Header for User Table Model
            column.add("MA DOC GIA");
            column.add("MA LOAI DOC GIA");
            column.add("HO TEN");
            column.add("GIOI TINH");
            column.add("NGAY SINH");
            column.add("DIA CHI");

            String sqlDG = "select * from DOCGIA";
            ResultSet rs = stmt2.executeQuery(sqlDG);

            while(rs.next()){
                Vector temp = new Vector();
                temp.add(rs.getString(1));
                temp.add(rs.getString(2));
                temp.add(rs.getString(3));
                temp.add(rs.getString(4));
                //temp.add(rs.getString(5));
                temp.add(formatDate.format(rs.getDate(5)));
                temp.add(rs.getString(6));

                data.add(temp);

            }
            modelDG = new DefaultTableModel(data, column) {

                @Override
                public boolean isCellEditable(int row, int column) {
                    return false;
                }
            };
            table_DOCGIA.setModel(modelDG);
            rs.close();
            stmt2.close();
            con1.close();
        }

        catch(SQLException se){
            JOptionPane.showMessageDialog(this, se.toString());
        }
        catch(ClassNotFoundException ce){
            JOptionPane.showMessageDialog(this, ce.toString());
        }
    }


    // Kiem tra rang buoc khi xoa doc gia
    public int Kiemtra(){
        try{
            Vector v = new Vector();
            v = (Vector) modelDG.getDataVector().elementAt(table_DOCGIA.getSelectedRow());
            String madocgia = v.elementAt(0).toString();
            Connection conn=null;
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            conn = DriverManager.getConnection(getURLConnection());

            String sqlSelect = "select MADOCGIA from PHIEUMUON";
            Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery(sqlSelect);
            while(rs.next()){
                String str=rs.getString("MADOCGIA");
                if(madocgia.equals(str))  // trung khoa chinh
                    return 0;
            }
        }
        catch(ClassNotFoundException ex){
                JOptionPane.showMessageDialog(this, ex.toString());
            }
        catch (SQLException ex) {
                //Logger.getLogger(frmMain.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(this,ex.toString());
            }
        return 1;

    }

    private void bt_XOAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_XOAActionPerformed
        // TODO add your handling code here:
        int Row[] = table_DOCGIA.getSelectedRows();
        if (Row.length > 1) {
            JOptionPane.showMessageDialog(null, "Ban chỉ được chọn một độc giả để xóa!");
            return;
        }
        if (table_DOCGIA.getSelectedRow() <0) {
            JOptionPane.showMessageDialog(null, "Hãy chọn độc giả để xóa!");
            return;
        }
        if(Kiemtra()==0){
            JOptionPane.showMessageDialog(null, "Không xóa được! độc giả này đang mượn sách.");
            return;
        } else {
            Vector v = new Vector();
            v = (Vector) modelDG.getDataVector().elementAt(table_DOCGIA.getSelectedRow());
            String madocgia = null;
            madocgia=v.elementAt(0).toString();

            String sqlDelete = "delete from DOCGIA where MADOCGIA = " + madocgia +"";
            if (JOptionPane.showConfirmDialog(null, "Bạn có chắc là muốn xóa độc giả " + v.elementAt(2)+ " không?", "Quản lý độc giả", JOptionPane.OK_CANCEL_OPTION) == 0) {
                try {
                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                    con1 = DriverManager.getConnection(getURLConnection());

                    CallableStatement cs = con1.prepareCall("{call xoaDG (?)}");
                    cs.setString(1, v.elementAt(0).toString());

                    int i=cs.executeUpdate();
                    if (i < 0) {
                        JOptionPane.showMessageDialog(null, "Xóa độc giả " + v.elementAt(2) + " không thành công!");
                    }
                    if (i > 0) {
                        JOptionPane.showMessageDialog(null, "Xóa độc giả " + v.elementAt(2) + " thành công!");
                    }
                    //JOptionPane.showMessageDialog(this, "Xóa thành công");
                    con1.close();
                } catch(ClassNotFoundException ex){
                    JOptionPane.showMessageDialog(this, ex.toString());
                } catch (SQLException ex) {
                    //Logger.getLogger(frmMain.class.getName()).log(Level.SEVERE, null, ex);
                    JOptionPane.showMessageDialog(this,ex.toString());
                }
            }
            SetModel();
        }
}//GEN-LAST:event_bt_XOAActionPerformed

    private void bt_SUAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_SUAActionPerformed
        // TODO add your handling code here:
        int Row[] = table_DOCGIA.getSelectedRows();
        if (Row.length > 1) {
            JOptionPane.showMessageDialog(null, "Ban chỉ được chọn một độc giả để sửa!");
            return;
        }

        if (table_DOCGIA.getSelectedRow() >= 0) {
            //suaDG sd = new suaDG(this);
            //sd.setVisible(true);

        } else {
            JOptionPane.showMessageDialog(null, "Hãy chọn độc giả để sửa!");
        }
}//GEN-LAST:event_bt_SUAActionPerformed

    private void bt_THEMActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_THEMActionPerformed
        // TODO add your handling code here:
        //themDG s =new themDG.
        //themDG them = new themDG(this);
        //them.setVisible(true);
}//GEN-LAST:event_bt_THEMActionPerformed

    
    public void loadtb_qlts()
    {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            try {
                Connection con = DriverManager.getConnection(getURLConnection());
                Statement stm =con.createStatement();            
                int i=0;
                ResultSet rs=stm.executeQuery("SELECT SACH.MASACH,SACH.TENSACH,PHIEUMUON.NGAYMUON FROM DOCGIA,PHIEUMUON,SACH_PHIEU,SACH WHERE DOCGIA.MADOCGIA='"+ tb_qlts_madg.getText() +"' AND DOCGIA.MADOCGIA=PHIEUMUON.MADOCGIA AND PHIEUMUON.MAPHIEU=SACH_PHIEU.MAPHIEU AND SACH_PHIEU.MASACH = SACH.MASACH AND SACH_PHIEU.NGAYTRA IS NULL");
                while(rs.next())
                {
                    tb_xemkq.setValueAt(rs.getString("MASACH"), i, 0);
                    tb_xemkq.setValueAt(rs.getString("TENSACH"), i, 1);
                    tb_xemkq.setValueAt(rs.getDate("NGAYMUON"), i, 2);
                    i++;
                }

                if(i<5)
                {
                    for(;i<5;i++)
                    {
                        tb_xemkq.setValueAt("", i, 0);
                        tb_xemkq.setValueAt("", i, 1);
                        tb_xemkq.setValueAt("", i, 2);
                    }
                }
            } catch (SQLException ex) {
                Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
            }

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(QLTV.class.getName()).log(Level.SEVERE, null, ex);
        }
    }     
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new QLTV().setVisible(true);
            }

        });
    }
    private String getURLConnection() {
        return "jdbc:sqlserver://" + server + ":" + port +
                ";databaseName=" + databaseName +
                ";User=" + username +
                ";Password=" + password;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel PNktdg;
    private javax.swing.JPanel PNkts;
    private javax.swing.JPanel PNms;
    private javax.swing.JPanel PNqldg;
    private javax.swing.JPanel PNqls;
    private javax.swing.JPanel PNts;
    private javax.swing.JButton bt_SUA;
    private javax.swing.JButton bt_THEM;
    private javax.swing.JButton bt_XOA;
    private javax.swing.JButton bt_qlms_chomuon;
    private javax.swing.JButton bt_qlms_huythaotac;
    private javax.swing.JButton bt_qlms_ktdg;
    private javax.swing.JButton bt_qlms_ktsach;
    private javax.swing.JButton bt_qls_sua;
    private javax.swing.JButton bt_qls_them;
    private javax.swing.JButton bt_qls_xoa;
    private javax.swing.JButton bt_qlts_huythaotac;
    private javax.swing.JButton bt_qlts_ktdg;
    private javax.swing.JButton bt_qlts_kts;
    private javax.swing.JButton bt_qlts_ts;
    private javax.swing.JButton btdangnhap;
    private javax.swing.JButton btdangxuat;
    private javax.swing.JComboBox cb_qls_linhvuc;
    private javax.swing.JComboBox cb_qls_ngonngu;
    private javax.swing.JComboBox cb_qls_nhacungcap;
    private javax.swing.JComboBox cb_qls_nhaxuatban;
    private javax.swing.JComboBox cb_qls_tacgia;
    private javax.swing.JCheckBox cb_qlts_matsach;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel39;
    private javax.swing.JLabel jLabel40;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lbketnoi;
    public javax.swing.JTable table_DOCGIA;
    private javax.swing.JTextField tb_qlms_diachi;
    private javax.swing.JTextField tb_qlms_doituong;
    private javax.swing.JTextField tb_qlms_gia;
    private javax.swing.JTextField tb_qlms_gioitinh;
    private javax.swing.JTextField tb_qlms_hoten;
    private javax.swing.JTextField tb_qlms_linhvuc;
    private javax.swing.JTextField tb_qlms_madg;
    private javax.swing.JTextField tb_qlms_mapm;
    private javax.swing.JTextField tb_qlms_mas;
    private javax.swing.JTextField tb_qlms_ngayhethan;
    private javax.swing.JTextField tb_qlms_ngaysinh;
    private javax.swing.JTextField tb_qlms_ngonngu;
    private javax.swing.JTextField tb_qlms_nhaxuatban;
    private javax.swing.JTextField tb_qlms_tacgia;
    private javax.swing.JTextField tb_qlms_tensach;
    private javax.swing.JTextField tb_qls_gia;
    private javax.swing.JTextField tb_qls_masach;
    private javax.swing.JTextField tb_qls_tensach;
    private javax.swing.JTextField tb_qlts_madg;
    private javax.swing.JTextField tb_qlts_mas;
    private javax.swing.JTextField tb_qlts_songayquahan;
    private javax.swing.JTextField tb_qlts_sosachmuon;
    private javax.swing.JTextField tb_qlts_tendg;
    private javax.swing.JTextField tb_qlts_xuphat;
    private javax.swing.JTable tb_xemkq;
    private javax.swing.JPasswordField tbpw;
    private javax.swing.JTabbedPane tbtag;
    private javax.swing.JTextField tbun;
    // End of variables declaration//GEN-END:variables

}
